package com.haixiaoke.saas.order.service;


import com.haixiaoke.saas.apartment.domain.HousingAllocation;
import com.haixiaoke.saas.apartment.domain.HousingPrice;
import com.haixiaoke.saas.apartment.domain.OrderVO;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.weChat.domain.ParseParam;
import com.haixiaoke.saas.common.weChat.domain.RefundParam;
import com.haixiaoke.saas.common.weChat.domain.RefundReqInfo;
import com.haixiaoke.saas.contract.domain.LesseeContract;
import com.haixiaoke.saas.house.domain.House;
import com.haixiaoke.saas.order.domain.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 订单Service接口
 *
 * @author qixi
 * @date 2024-03-04
 */
public interface IOrderService {
    /**
     * 查询订单
     *
     * @param orderId 订单主键
     * @return 订单
     */
    Order selectOrderByOrderId(String orderId);

    Order selectOrderById(String orderId);

    /**
     * 查询订单列表
     *
     * @param order 订单
     * @return 订单集合
     */
    List<Order> selectOrderList(Order order);

    /**
     * 新增订单
     *
     * @param order 订单
     * @return 结果
     */
    int insertOrder(Order order);

    /**
     * 新增预订单
     *
     * @param order 订单
     * @return 结果
     */
    Order insertPreOrder(Order order);

    /**
     * 修改订单
     *
     * @param order 订单
     * @return 结果
     */
    int updateOrder(Order order);

    /**
     * 修改订单
     *
     * @param order 订单
     * @return 结果
     */
    int updateOrderBySystem(Order order);

    /**
     * 批量删除订单
     *
     * @param orderIds 需要删除的订单主键集合
     * @return 结果
     */
    int deleteOrderByOrderIds(String[] orderIds);

    /**
     * 删除订单信息
     *
     * @param orderId 订单主键
     * @return 结果
     */
    int deleteOrderByOrderId(String orderId);

    List<Order> selectOrderValidList(Order order);

    /**
     * 房态订单查询
     *
     * @param order
     * @return
     */
    List<OrderVO> conditionList(Order order);

    /**
     * 房态订单查询-卡片模式
     *
     * @param house
     * @return
     */
    List<House> conditionCard(House house);

    int signOrder(LesseeContract lesseeContract);

    Boolean checkRepeatOrder(Order order);

    void refundRent(Order order);

    void relet(Order order);

    void exchangeHouse(Order order);


    void sublease(Order order);

    void orderOvertimeTask();

    void preOrderSignOvertimeTask();


    /**
     * 查询下单所需数据
     *
     * @param houseId
     * @return
     */
    ConfirmationVO confirmation(String houseId);

    /**
     * @param startTime        开始时间
     * @param endTime          结束时间
     * @param orderId          缓存的订单id
     * @param linkedOrderId    续租订单
     * @param allocation       房屋配置
     * @param housingPriceList 房屋配置的房费数据
     * @param isExpenses       是否需要记录每日收费结果,true为记录
     * @param createBy         创建者
     * @return
     */
    ConfirmationVO compute(Date startTime, Date endTime, String orderId, String linkedOrderId, HousingAllocation allocation, List<HousingPrice> housingPriceList, boolean isExpenses, String createBy);

    /**
     * 提交短租订单
     *
     * @param dto
     * @param vo
     * @return
     */
    Order placeOrder(OrderDTO dto, ConfirmationVO vo);

    /**
     * 校验短租订单的租赁时间是否重叠
     *
     * @param startTime
     * @param endTime
     * @param houseId
     * @return
     */
    boolean checkRepeatShortOrder(Date startTime, Date endTime, String houseId);

    /**
     * 微信支付订单回调业务
     *
     * @param parseParam
     */
    void payCallbackOrder(ParseParam parseParam);

    /**
     * 根据登录用户查询订单
     *
     * @param order
     * @return
     */
    List<Order> selectOrderByUserId(Order order);

    /**
     * 根据登录用户查询退款订单
     *
     * @param order
     * @return
     */
    List<Order> selectRefundOrderByUserId(Order order);

    /**
     * 小程序查询订单详情
     *
     * @param orderId
     * @return
     */
    Order miniSelectOrderByOrderId(String orderId);

    /**
     * 小程序查询退款订单详情
     * @param orderId
     * @return
     */
    Order miniSelectRefundOrderByOrderId(String orderId);

    /**
     * C端用户取消订单
     *
     * @param orderId
     * @return
     */
    int frontCancelledOrder(String orderId);

    /**
     * C端用户删除订单
     *
     * @param orderId
     * @return
     */
    int frontDeletedOrder(String orderId);

    /**
     * 订单统计退款金额
     *
     * @param orderId
     * @param isRefund 是否记录退房详细过程
     * @return
     */
    OrderRefundVO reservationComputeRefund(String orderId, boolean isRefund);

    /**
     * 退房订单统计退款金额
     *
     * @param orderId
     * @return
     */
    OrderRefundVO refundComputeRefund(String orderId, Date realityCheckOutTime);

    /**
     * 预订订单取消预订
     *
     * @return
     */
    int cancelReservation(OrderStateRecord orderStateRecord, String userName, Long userId, String auditSource);

    /**
     * 查询公寓订单列表
     */
    List<Order> selectApartmentOrderList(Order order);

    /**
     * 预订订单退款
     * @param reqInfo
     */
    void cancelReservationCallbackOrder(RefundParam refundParam,RefundReqInfo reqInfo);

    Order selectApartmentOrderByOrderId(String orderId);

    Order selectHouseDynamicOrderByOrderId(String orderId);

    /**
     * 短租订单代入住->已入住
     * @param recordSource  操作来源
     * @param userId        操作用户id
     */
    int checkIn(Order order, String recordSource, Long userId);

    /**
     * 检验续租订单是否是未支付
     * @param orderId
     * @return
     */
    boolean checkLinkedOrderState(String orderId);

    /**
     * 公寓订单换房
     * @param order
     * @return
     */
    int apartmentExchangeHouse(Order order);

    /**
     * 短租订单已入住订单--续租
     */
    int apartmentRelet(Order order);

    /**
     * 短租订单已入住订单--退房中
     */
    int apartmentCheckingOut(Order order);

    /**
     * 查看退房中退房金额详细信息
     */
    Order apartmentCheckingOutInfo(String orderId);

    OrderPriceVO packageOrderPriceVO(List<OrderChargeItem> chargeItemList, List<OrderHousingExpenses> housingExpensesList,
                                            List<OrderRefundItem> orderRefundItemList, List<OrderRefundDetails> refundDetailsList,
                                            OrderHouseInspection orderHouseInspection);

    /**
     * 短租订单退房订单--已完成（退费处理）
     */
    AjaxResult apartmentCompleted(Order order);

    /**
     * 支付超时
     * @param orderId
     */
    void paymentTimeout(String orderId);

    /**
     * 退房回调任务
     */
    void checkOutCallbackOrder(RefundParam refundParam, RefundReqInfo reqInfo);

    Map<String,Object> countOrderState(Long userId);

    List<Order> selectOrderByLinkedOrderId(String orderId);

    /**
     * 查最新的续租订单
     *
     * @param orderId
     * @return
     */
    Order selectNewOrderByLinkedOrderId(String orderId);

    String checkLinkedOrder(String orderId);

    List<Order> selectOrderByHouseIds(String[] houseIds);

    List<Order> selectOrderByHouseIdAndCheckIn(String houseId);

    /**
     * 订单审核超时,自动通过审核
     *
     * @param recordId
     */
    void reviewCancelReservationOrderTimeOut(Long recordId);

    List<Order> selectAddBillList(Order order);

    /**
     * 查询房屋租赁时间列表
     * @param houseId
     * @return
     */
    List<OrderVO> selectRentTimeList(String houseId);

    /**
     * 订单作废
     *
     * @param orderId
     */
    AjaxResult cancel(String orderId);

    List<Order> selectEffectiveOrderByHouseId(String houseId);

    /**
     * 短租订单续租支付成功回调授权智能锁人脸业务
     *
     * @param order
     */
    void authorizedFace(Order order);

    boolean checkReturnOrderByOrderId(String orderId);
}
